package com.typhoon.spring_shiro.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.typhoon.spring_shiro.entity.Role;

@Repository("roleDao")
public class RoleDao extends BaseDao implements ICommonDao<Role, Long> {
	
	private static final Logger logger = LoggerFactory.getLogger(RoleDao.class);
	
	private static final String TABLE_ROLE = "Role";
	
	private static final String TABLE_USER_ROLE = "UserRole";

	@Resource
	private JdbcTemplate financialJdbc;
	
	@Override
	public Role queryByPrimaryKey(Long primaryKey) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByPrimaryKey(Long primaryKey) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Role get(Object paramObject) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Role> list(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Role> list(Object paramObject) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(Role paramE) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long count(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long count(Object paramObject) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Role save(Role paramE) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Role> listAllByUserId(Long userId) {
		Assert.notNull(userId);
		StringBuilder sql = new StringBuilder();
		sql.append(select);
		sql.append(" r.* ");
		sql.append(from);
		sql.append(TABLE_ROLE).append(" r ");
		sql.append(" LEFT JOIN  ").append(TABLE_USER_ROLE).append(" ur on r.id = ur.roleId");
		sql.append(where);
		sql.append("ur.userId = ? ");
		logger.debug("根据用户id查询角色信息sql-{}",sql.toString());
		return this.queryList(financialJdbc, Role.class, sql.toString(), new Object[]{userId});
	}
	
	

}
